<template>
	<!-- 发表评论： -->
	<view class="publishComment mainpadding mainbgc">
		<view class="mainpadding border-r1 ffffff">
			<view class="commentBox flexleft">
				<view class="commentTitle margin-right">酒店评价</view>
				<u-rate count="5" v-model="value" active-color="#00D2E1" inactive-color="#DCDCDC" size="30"></u-rate>
			</view>
			<view class="margin-top">
				<u--textarea v-model="TextValue" placeholder="请输入您的评价~"></u--textarea>
			</view>
			<!-- 选择图片： -->
			<view class="flexleft">
				<view class="itembox flexcenter" v-for="(item,index) in upImg" :key="index">
					<view class="choosePic margin-top">
						<view class="addPic">
							<image :src="item" mode=""></image>
						</view>
						<view class="xiaotubiao" @click="deleimage(index)">
							<image src="../../static/images/my/chahao.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="itembox flexcenter" @click="" v-if="upImg.length>=4?false:true">
					<view class="choosePic margin-top" @click="uploadImg">
						<view class="addPic">
							<image src="../../static/images/my/camera.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 按钮： -->
		<view class="publishBtn-box">
			<view class="publishBtn" @click="submit()">发表</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				value: 0,
				TextValue: '',
				listid: "",
				upImg: [],
				type:"",//2商品评价
			}
		},
		onLoad(options) {
			this.listid = options.id
		},
		methods: {
			submit() {
				uni.showLoading({
					mask: true,
					title: '请稍候...',
				})
				if (this.value == 0) {
					httpRequest.toast("请进行打分")
					return false
				}
				if (this.TextValue == "") {
					httpRequest.toast("请输入评价内容")
					return false
				}
				httpRequest.request('api/order/commentOrder', 'POST', {
					id: this.listid,
					star: this.value,
					content: this.TextValue,
					images: this.upImg.join()
				}).then(resp => {
					if (resp.code == 1) {
						uni.hideLoading();
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					}
					httpRequest.toast(resp.msg)
				})
			},
			uploadImg() {
				let _this = this;
				let upImgs = _this.upImg;
				let num = 4 - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url, upImg) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(image_item);
				}).catch(err => {});
			},
			deleimage(i) {
				this.upImg.splice(i, 1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.choosePic {
		position: relative;
	}

	.xiaotubiao {
		position: absolute;
		top: -5rpx;
		right: -5rpx;

		image {
			width: 26rpx;
			height: 26rpx;
		}
	}

	.itembox {
		width: 25%;
	}

	.all {
		padding-bottom: 150rpx;
	}

	.addPic {
		width: 150rpx;
		height: 150rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.publishBtn-box {
		position: fixed;
		bottom: 30rpx;
		width: calc(100vw - 60rpx);

		.publishBtn {
			border-radius: 41rpx;
			background-color: #00D2E1;
			padding: 18rpx 0;
			text-align: center;
			color: #fff;
			width: 100%;
		}
	}
</style>
